#include "../include/geometryPolygon.hpp"

namespace geometry {

Polygon::Polygon(const std::vector<std::pair<double, double>>& vertices) : vertices_(vertices) {
    if (vertices_.size() < 3) {
        throw std::invalid_argument("Polygon must have at least 3 vertices.");
    }
}

double Polygon::getArea() const {
    double area = 0.0;
    size_t n = vertices_.size();
    for (size_t i = 0; i < n; ++i) {
        size_t j = (i + 1) % n;
        area += (vertices_[i].first * vertices_[j].second - vertices_[j].first * vertices_[i].second);
    }
    return std::abs(area) / 2.0;
}

} // namespace geometry